package edu.nanyang.struts;

import java.util.List;

import org.apache.struts2.ServletActionContext;
import org.apache.struts2.json.annotations.JSON;

import com.opensymphony.xwork2.ActionSupport;

import edu.nanyang.domain.City;
import edu.nanyang.domain.School;
import edu.nanyang.hibernate.service.ISchoolService;

@SuppressWarnings("serial")
public class SchoolAction extends ActionSupport {
	private ISchoolService schoolService;
	private List<School> list;
	private int cityId;
	private String schoolName;
	private String result;
	
	public String addSchool(){
		School s=new School();
		s.setName(schoolName);
		result=this.schoolService.addSchool(s, cityId);
		return SUCCESS;
	}
	public String acquireSchoolByCityId() {
		System.out.println("cityId=" + cityId);
		list = this.schoolService.acquireSchoolByCityId(cityId);
		return SUCCESS;
	}
	@JSON(serialize=false)
	public String getCurSchoolByCurCityId(){
		Object o=ServletActionContext.getRequest().getSession().getAttribute("city");
		if(o==null){
			list=this.schoolService.acquireSchoolByCityId(3);
		}else{
			list=this.schoolService.acquireSchoolByCityId(((City)o).getId());
		}
		return SUCCESS;
	}
	
	public String getResult() {
		return result;
	}
	public void setResult(String result) {
		this.result = result;
	}
	public String getSchoolName() {
		return schoolName;
	}
	public void setSchoolName(String schoolName) {
		this.schoolName = schoolName;
	}
	public List<School> getList() {
		return list;
	}

	public void setList(List<School> list) {
		this.list = list;
	}

	public int getCityId() {
		return cityId;
	}

	public void setCityId(int cityId) {
		this.cityId = cityId;
	}

	public void setSchoolService(ISchoolService schoolService) {
		this.schoolService = schoolService;
	}

}
